package tools.vcf.bisSNP;

import java.io.BufferedReader;

public class BisSNPbedEntryParser {

	private BufferedReader reader;
	private BisSNPbedEntry curEntry, nextEntry;
	private boolean hasNext;
	
	public BisSNPbedEntryParser(BufferedReader br) throws Exception{
		reader=br;

		readNext();
	}
	
	
	
	public boolean hasNext() {
		return hasNext;
	}

	public BisSNPbedEntry next() throws Exception{
		if(!hasNext()){
			throw new Exception("No more entries in file");
		}
		curEntry= new BisSNPbedEntry(nextEntry);
		readNext();
		return curEntry;
	}

	private void readNext() throws Exception{
		hasNext=false;
		String s=reader.readLine();
		while(s!=null && s.startsWith("#")){
			s=reader.readLine();
		}
		if(s!=null){
			try{
			nextEntry= new BisSNPbedEntry(s);
			hasNext= true;
			}catch(Exception e){
				readNext();
			}
		}
	}
}
